#include <iostream>
using namespace std;

// 实现两个数字进行交换
void swap1(int a, int b)
{
    int temp = a;
    a = b;
    b = temp;

    cout << "swap1中，a = " << a << endl;
    cout << "swap1中，b = " << b << endl;
}


void swap2(int *p1, int *p2)
{
    int temp = *p1;
    *p1 = *p2;
    *p2 = temp;
}

int main()
{
    //指针与函数
    //1、值传递
    int a = 20;
    int b = 99;
    swap1(a,b);

    cout << "值传递后：" << endl;
    cout << "a = " << a << endl;
    cout << "b = " << b << endl;

    //2、地址传递
    //如果是地址传递，可以改变实参
    swap2(&a,&b);

    cout << "地址传递后：" << endl;
    cout << "a = " << a << endl;
    cout << "b = " << b << endl;

    return 0;
}